<?php


namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
use think\cache\driver\Redis;

class Test extends  Base
{

    public function insertxmcdz(){
        for ($i = 80327; $i< 80372 ;$i ++){
            echo $i."<br>";
            Db::execute("INSERT INTO lis_xmcdz ( yqdh, cdrq, ybbh, xmdh, xmcdz, operator, yscdz, Fucha, JiaZuo )
 VALUES ( 'C501', {ts '2021-06-04 00:00:00.000'}, :ybbh, 'TP', '', '', '', 0, 0 )
",['ybbh'=>$i]);
        }
    }

    public function web(){
        return view();
        //header("Content-type:application/json;charset=utf-8");
        $url = "https://hbwjw.gssjy.com:8443/test_hbhsjc/api/v1/batchImportTubeResult";
        $data = array(
            "SGTXM" =>"YBZX100010001",
            "JCJG" =>"阴性",
            "JCRQ" => "2021-09-19 13:50:10",
        );
        $param = array(
            //注册字段
            "app_id" => "e3713508add4472b88f5f7c7e743b81f",
            "app_secret" => "6b04a5edb7fa40a984682926086bde0b",
            "data"=> $data
        );
        $datas = json_encode($param, true);


        list($returnCode, $returnContent) = $this->http_post_json($url, $datas);


        var_dump($returnContent);//return_code是http状态码


        //
    }

    public  function http_post_data($url, $data_string)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                "Content-Type: application/json; charset=utf-8",
                "Content-Length: " . strlen($data_string))
        );
        ob_start();
        curl_exec($ch);
        $return_content = ob_get_contents();
        return curl_exec($ch);



    }

    public  function http_post_json($url, $jsonStr)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json; charset=utf-8',
                'Content-Length: ' . strlen($jsonStr)
            )
        );
        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        return array($httpCode, $response);
    }


    public function clientRadi(){
     /*   echo phpinfo();
     has() get() set() inc() dec() rm() clear() 这七个
        exit();*/
        $redis = new Redis();
        $redis->set('names','my name is andy');
        dump($redis->get('names'));die;

    }
    public function zac(){
        $data = Db::connect("database_zAc247")->table("user")->select();
        var_dump($data);
        exit();
    }


    public function ac(){
        $data = array('1'=>'ac');
        echo $data;
        echo phpinfo();
        exit();

        $data = Db::query("select yqdh,ybbh,cdrq from lis_ybxx where ybid in ('611110009529','611110009607','611110009766','611110009586','611110009589','611110009805','611110009741','611110009611','611110009752','611110009777','611110009609','611110010488','611110009765','611110009771','611110009546','611110009705','611110009688','611110010497','611110009762','611110009746','611110009526','611110009802','611110009531','611110009508','611110009681','611110009555','611110009562','611110009524','611110009530','611110009789','611110009652','611110010491','611110009788','611110009514','611110010487','611110009782','611110009506','611110009785','611110009761','611110009753','611110010494','611110010504','611110009801','611110009776','611110009754','611110010503','611110009778','611110009779','611110009791','611110010493','611110009672','611110009629','611110009631','611110009614','611110009665','611110009676','611110009653','611110009695') and yqdh = 'c501'
");
        foreach ($data as $cc=>$val){
            $cc = Db::execute("INSERT INTO lis_xmcdz ( yqdh, cdrq, ybbh, xmdh, xmcdz, operator, yscdz, Fucha, JiaZuo )
 VALUES ( 'C501', ?, ?, 'TC', '1', '', '1', 0, 0 )",[$val['cdrq'],$val['ybbh']]);
        }
        var_dump($cc);
    }

    public  function index(){

        var_dump(1);
        exit();
        $data = Db::query("SELECT a.dh,a.password FROM dbo.xt_yymc_print a LEFT JOIN 
zAc_hospital b ON a.dh = b.dh where b.creatime >'2020-05-08 01:26:35.000'");

      /* var_dump($data);*/


        echo  rand(10000,500000);
    }

       function getActive($navc){
        $c = request()->controller();
        if(strtolower($navc) == $c) {
            return 'active';
        }
        return '';
    }
    public  function test(){
        $res = Model('report')->GetReportInfoByYbid('610000123456');
        if(!$res){
            var_dump($res);
        }
    }

    public  function session(){
        Session::set('userinfo','1');
        var_dump(Session::get('userinfo'));

    }

    public  function zac_tmp(){
        $res = Db::table('zac_tmp')->find();
        $res2 = Db::query('SELECT * FROM zac_tmp');
     /*   foreach ($res2 as $aa){
            $aa['']
        }*/
        dump($aa);exit();
    }

    //调用去重函数
    public function cul(){
        $dh = '610000';
        $dh = $dh.'%';
        $TestDate = date("Y-m-d H:i:s", strtotime("-30 day"));
        $res = Db::execute('UPDATE dbo.Lis_ReportTasks SET ProcessFlag =0 WHERE Barcode like :Barcode and TestDate > :TestDate',
            ['Barcode'=>$dh, 'TestDate'=>$TestDate]);
    }




}